home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / x / srgp_col.c next >
Encoding:
C/C++ Source or Header  |  1992-09-11  |  6.7 KB  |  238 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** THIS FILE IS FOR X11 IMPLEMENTATION ONLY
  5. **/
  6.  
  7. void 
  8. SRGP__initColor (requested_planes)
  9. {
  10.    srgp__visual_class = DefaultVisual(srgpx__display, srgpx__screen)->class;
  11.    srgp__available_depth = DefaultDepth(srgpx__display, srgpx__screen);
  12.  
  13.    if (srgp__available_depth == 1 || srgp__visual_class == StaticGray) {
  14.  
  15.       /***** PERFORMED FOR BILEVEL DISPLAYS */
  16.  
  17.       SRGP_BLACK = 1;
  18.       SRGP_WHITE = 0;
  19.       srgp__application_depth = srgp__max_pixel_value = 1;
  20.       srgp__base_colorindex = 0;
  21.    }
  22.    
  23.  
  24.    else {
  25.  
  26.       /****** PERFORMED FOR COLOR DISPLAYS */
  27.  
  28.       SRGP_BLACK = 1;
  29.       SRGP_WHITE = 0;
  30.  
  31.       if (requested_planes < 0) {
  32.      fprintf (stderr, "Fatal Error: insane parameter to SRGP_begin()\n\
  33.             Application requesting negative number of planes.\n");
  34.      exit(1);
  35.       }
  36.       if ((requested_planes == 0) || 
  37.       (requested_planes > srgp__available_depth)) 
  38.      srgp__application_depth = srgp__available_depth;
  39.       else
  40.      srgp__application_depth = requested_planes;
  41.       srgp__max_pixel_value = (1 << srgp__application_depth) - 1;
  42.  
  43.       if (srgp__application_depth == srgp__available_depth) {
  44.  
  45.      /***** APPL WANTS ENTIRE COLOR TABLE! */
  46.      srgpx__colormap = 
  47.         XCreateColormap (srgpx__display, 
  48.                  srgp__curActiveCanvasSpec.drawable.win,
  49.                  DefaultVisual(srgpx__display,srgpx__screen),
  50.                  AllocAll);
  51.      XSetWindowColormap (srgpx__display, 
  52.                  srgp__curActiveCanvasSpec.drawable.win,
  53.                  srgpx__colormap);
  54.       }
  55.       else {
  56.  
  57.      /***** APPL WANTS TO SHARE COLOR TABLE WITH THE OTHER CLIENTS */
  58.      unsigned long return_masks_here[8];
  59.      unsigned long return_pixels_here[1];
  60.      Status result;
  61.  
  62.      srgpx__colormap = DefaultColormap(srgpx__display,srgpx__screen);
  63.  
  64.      result = 
  65.         XAllocColorCells (srgpx__display,
  66.                   srgpx__colormap,
  67.                   TRUE /* contiguous planes desired */,
  68.                   return_masks_here,
  69.                   srgp__application_depth,
  70.                   return_pixels_here,
  71.                   1);
  72.      if (result == 0) {
  73.         fprintf (stderr, "%s\n%s\n%s\n%s\n%s\n",
  74.              "SRGP: Color table too full to share.",
  75.              "A solution is to have the SRGP application request",
  76.              "   0 planes in the 4th parameter to SRGP_begin.",
  77.              "For now, the application will have its own",
  78.              "   color table, rather than try to share.");
  79.         
  80.         srgpx__colormap = 
  81.         XCreateColormap (srgpx__display, 
  82.                  srgp__curActiveCanvasSpec.drawable.win,
  83.                  DefaultVisual(srgpx__display,srgpx__screen),
  84.                  AllocAll);
  85.         XSetWindowColormap (srgpx__display, 
  86.                 srgp__curActiveCanvasSpec.drawable.win,
  87.                 srgpx__colormap);
  88.         srgp__base_colorindex = 0;
  89.      } else
  90.          srgp__base_colorindex = return_pixels_here[0];
  91.       }
  92.  
  93.       /* Only first two entries of LUT are init'd */
  94.       XStoreNamedColor 
  95.      (srgpx__display, srgpx__colormap, "white", COLORINDEX(0), -1);
  96.       XStoreNamedColor 
  97.      (srgpx__display, srgpx__colormap, "black", COLORINDEX(1), -1);
  98.    }
  99.  
  100.  
  101.    /*** DONE FOR ALL CONFIGURATIONS. */
  102.    XSetWindowBackground (srgpx__display, 
  103.              srgp__curActiveCanvasSpec.drawable.win, XWHITE);
  104.    XSetWindowBorder (srgpx__display, 
  105.              srgp__curActiveCanvasSpec.drawable.win, XBLACK);
  106. }
  107.  
  108.  
  109.  
  110. void SRGP_loadColorTable
  111.    (int startentry, int count,
  112.     unsigned short *redi, 
  113.     unsigned short *greeni,
  114.     unsigned short *bluei)
  115. {
  116.    static XColor *x_color_structs = NULL;
  117.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  118.    register int i,j;
  119.    int endi;
  120.    register XColor *xcurcs;
  121.  
  122.  
  123.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  124.    if (srgp__available_depth == 1 || srgp__visual_class == StaticGray)
  125.       return;
  126.  
  127.    endi = startentry + count;
  128.  
  129.    DEBUG_AIDS{
  130.       SRGP_trace (SRGP_logStream, "SRGP_loadColorTable  %d  %d  %x %x %x\n",
  131.           startentry, count, redi, greeni, bluei);
  132.  
  133.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  134.       srgp_check_pixel_value (startentry, "start");
  135.       srgp_check_pixel_value (endi-1, "end");
  136.    }
  137.  
  138.  
  139.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  140.    if (cursize_of_x_cs_array < count) {
  141.       if (x_color_structs)
  142.      free ((char*)x_color_structs);
  143.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  144.       cursize_of_x_cs_array = count;
  145.  
  146.       /* Initialize a constant field of the XColor structs. */
  147.       for (i=0; i<count; i++)
  148.      x_color_structs[i].flags = -1;
  149.    }
  150.  
  151.    /* COPY INTENSITY VALUES INTO ARRAY. */
  152.    for (i=startentry, j=0, xcurcs=x_color_structs; i<endi; i++,j++,xcurcs++){
  153.       xcurcs->pixel = COLORINDEX(i);
  154.       xcurcs->red = redi[j];
  155.       xcurcs->green = greeni[j];
  156.       xcurcs->blue = bluei[j];
  157.    }
  158.  
  159.    XStoreColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  160. }
  161.  
  162.  
  163.  
  164.  
  165. void
  166. SRGP_inquireColorTable 
  167.    (int startentry, int count,
  168.     unsigned short *redi, 
  169.     unsigned short *greeni,
  170.     unsigned short *bluei)
  171. {
  172.    static XColor *x_color_structs = NULL;
  173.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  174.    register int i,j;
  175.    int endi;
  176.    register XColor *xcurcs;
  177.  
  178.  
  179.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  180.    if (srgp__available_depth == 1 || srgp__visual_class == StaticGray)
  181.       return;
  182.  
  183.    endi = startentry + count;
  184.  
  185.    DEBUG_AIDS{
  186.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  187.       srgp_check_pixel_value (startentry, "start");
  188.       srgp_check_pixel_value (endi-1, "end");
  189.    }
  190.  
  191.  
  192.    /* !!!!!! LATER, THIS SHOULD USE SAME ARRAY AS IN color_X11.c */
  193.  
  194.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  195.    if (cursize_of_x_cs_array < count) {
  196.       if (x_color_structs)
  197.      free ((char*)x_color_structs);
  198.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  199.       cursize_of_x_cs_array = count;
  200.    }
  201.  
  202.    for (i=startentry, xcurcs=x_color_structs; i<endi; i++,xcurcs++) {
  203.       xcurcs->pixel = COLORINDEX(i);
  204.       xcurcs->flags = -1;
  205.    }
  206.  
  207.    XQueryColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  208.  
  209.  
  210.    /* COPY INTENSITY VALUES INTO USER'S ARRAY. */
  211.    for (j=0, xcurcs=x_color_structs; j<count; j++,xcurcs++){
  212.       redi[j] = xcurcs->red;
  213.       greeni[j] = xcurcs->green;
  214.       bluei[j] = xcurcs->blue;
  215.    }
  216. }
  217.  
  218.  
  219.  
  220.  
  221. void
  222. SRGP_loadCommonColor (entry, name)
  223. int entry;
  224. char *name;   /* Null-terminated string of characters */
  225. {
  226.    /* IGNORE IF MONOCHROME */
  227.    if (srgp__available_depth == 1 || srgp__visual_class == StaticGray)
  228.       return;
  229.  
  230.    DEBUG_AIDS{
  231.       SRGP_trace (SRGP_logStream, "SRGP_loadCommonColor  %d  %s\n", entry, name);
  232.       srgp_check_pixel_value (entry, "start/end");
  233.    }
  234.  
  235.    XStoreNamedColor 
  236.       (srgpx__display, srgpx__colormap, name, COLORINDEX(entry), -1);
  237. }
  238.